package com.sgb.zhaocai.base;

import android.app.Activity;
import android.content.Context;

import com.alibaba.android.arouter.facade.template.IProvider;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sgb.zhaocai.service.TenderPurchaseApi;
import com.swgk.core.BuildConfig;
import com.swgk.core.base.aroute.ARouterStartWebBase;
import com.swgk.core.base.api.APIManager;
import com.swgk.core.base.aroute.provider.WebViewProvider;

import java.util.HashMap;
import java.util.Map;

/**
 * Time:2021/7/2
 * AUTHOR:F_Q
 * Description:
 */
public class BaseApi {
    public static final String RESPONSE_OK = "ok";
    static TenderPurchaseApi tenderPurchaseApi;
    private static Map<Class<? extends IProvider>, IProvider> iProviders;
    private static BaseApi instance;

    public static TenderPurchaseApi getApi() {
        if (tenderPurchaseApi == null) {
            tenderPurchaseApi =  APIManager.getInstance().create(TenderPurchaseApi.class);
        }
        return tenderPurchaseApi;
   //     return  APIManager.getInstance().create(TenderPurchaseApi.class);
    }

    private BaseApi() {
        iProviders = new HashMap<>();
    }

    public static BaseApi getInstance() {
        if (instance == null) {
            synchronized (BaseApi.class) {
                if (instance == null) {
                    instance = new BaseApi();
                }
            }
        }
        return instance;
    }
    public static void startWeb(Context context, String url) {
        ARouterStartWebBase.start(context,url);
    }

    public static void startWeb(Activity context, String url, int requestCode) {
        ARouterStartWebBase.start(context,url,requestCode);
    }

    public static void WebSiteInfo(String NO, int type) {
        ARouterStartWebBase.startWebSiteInfo(NO,type);
    }

    public <T extends IProvider> T getProvider(Class<T> service) {
        T navigation = (T) iProviders.get(service);
        if (navigation == null) {
            navigation = ARouter.getInstance().navigation(service);
            iProviders.put(service, navigation);
        }
        return navigation;
    }

    public void startAuctionPublish(Context context,int code) {
        // WebViewX5HostActivity.start(fragment.getActivity(), url);
        WebViewProvider navigation = getProvider(WebViewProvider.class);
        if (navigation != null) {
            navigation.startAuctionPublish(context,code);
        }
    }
}
